package com.acwing.partition13;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/2/13 16:05
 */
public class AC1275最大数 {

    private static final int N = 200010;
    private static Node[] tr = new Node[4 * N];
    private static int cnt = 0, m = 0, p = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        m = Integer.parseInt(ss[0]);
        p = Integer.parseInt(ss[1]);
        build(1, 1, m);
        long last = 0;
        for (int i = 0; i < m; i++) {
            ss = reader.readLine().split(" ");
            int x = Integer.parseInt(ss[1]);
            if (ss[0].charAt(0) == 'Q') {
                //查询最后x个数的最大数
                last = query(1, cnt - x + 1, cnt);
                writer.write(last + "\n");
            } else {
                //向序列后面添加一个数
                modify(1, ++cnt, (int) ((last + x) % p));
            }
        }
        writer.flush();
    }

    //单点修改，将x位置的值改为v
    private static void modify(int u, int x, int v) {
        if (tr[u].l == x && tr[u].r == x) tr[u].val = v;
        else {
            int mid = tr[u].l + tr[u].r >> 1;
            if (x <= mid) modify(u << 1, x, v);
            else modify(u << 1 | 1, x, v);
            pushUp(u);
        }
    }

    private static int query(int u, int l, int r) {
        //树中节点已经被完全包含在[l, r]区间内
        if (l <= tr[u].l && r >= tr[u].r) return tr[u].val;
        int mid = tr[u].l + tr[u].r >> 1, val = -0x3f3f3f3f;
        //如果和左边有交集，则递归查询左边；如果和右边有交集，则递归查询右边
        if (l <= mid) val = Math.max(val, query(u << 1, l, r));
        if (r > mid) val = Math.max(val, query(u << 1 | 1, l, r));
        return val;
    }

    private static void pushUp(int u) {
        //由子节点的信息来计算父节点的信息
        tr[u].val = Math.max(tr[u << 1].val, tr[u << 1 | 1].val);
    }

    private static void build(int u, int l, int r) {
        tr[u] = new Node(l, r);
        if (l == r) return;
        int mid = l + r >> 1;
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
    }

    private static class Node {
        private int l, r;
        private int val;

        public Node(int l, int r) {
            this.l = l;
            this.r = r;
        }
    }
}
